I updated the error states to use say_status.
Add text to the empty error
The empty error looked odd with the say_status change.
Update all stderr messages
Switch them to format statements and create a helper for the error
status.
None => Ok(None),
Some(err) => {
Err(match err.exit.as_ref().and_then(|e| e.code()) {
- Some(i) => CliError::new("", i),
+ Some(i) => CliError::new("bench failed", i),
None => CliError::from_error(Human(err), 101)
})
}
None => Ok(None),
Some(err) => {
Err(match err.exit.as_ref().and_then(|e| e.code()) {
- Some(i) => CliError::new("", i),
+ Some(i) => CliError::new("test failed", i),
None => CliError::from_error(Human(err), 101)
})
}
}
pub fn error<T: ToString>(&mut self, message: T) -> CargoResult<()> {
- self.err().say(message, RED)
+ self.err().say_status("error", message.to_string(), RED)
}
pub fn warn<T: ToString>(&mut self, message: T) -> CargoResult<()> {
// For fatal errors, print to stderr;
// and for others, e.g. docopt version info, print to stdout.
fn output(err: String, shell: &mut MultiShell, fatal: bool) {
- let std_shell = if fatal {shell.err()} else {shell.out()};
- let color = if fatal {RED} else {BLACK};
- let _ = std_shell.say(err, color);
+ let (std_shell, color, message) = if fatal {
+ (shell.err(), RED, Some("error"))
+ } else {
+ (shell.out(), BLACK, None)
+ };
+ let _ = match message{
+ Some(text) => std_shell.say_status(text, err.to_string(), color),
+ None => std_shell.say(err, color)
+ };
}
pub fn handle_error(err: CliError, shell: &mut MultiShell) {
let hide = unknown && shell.get_verbose() != Verbose;
if hide {
- let _ = shell.err().say("An unknown error occurred", RED);
+ let _ = shell.err().say_status("error", "An unknown error occurred", RED);
} else {
output(error.to_string(), shell, fatal);
}
pub static RUNNING: &'static str = " Running";
pub static COMPILING: &'static str = " Compiling";
+pub static ERROR: &'static str = " error";
pub static DOCUMENTING: &'static str = " Documenting";
pub static FRESH: &'static str = " Fresh";
pub static UPDATING: &'static str = " Updating";
-use support::{project, execs};
+use support::{project, execs, ERROR};
use support::registry::Package;
use hamcrest::assert_that;
"#);
assert_that(foo.cargo_process("build").arg("-v")
.arg("--target=nonexistent-target"),
- execs().with_status(101).with_stderr("\
-expected table for configuration key `target.nonexistent-target`, but found string in [..]config
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} expected table for configuration key `target.nonexistent-target`, \
+but found string in [..]config
+",
+ error = ERROR)));
});
test!(bad2 {
proxy = 3.0
"#);
assert_that(foo.cargo_process("publish").arg("-v"),
- execs().with_status(101).with_stderr("\
-Couldn't load Cargo configuration
+ execs().with_status(101).with_stderr(&format!("\
+{error} Couldn't load Cargo configuration
Caused by:
failed to load TOML configuration from `[..]config`
Caused by:
found TOML configuration value of unknown type `float`
-"));
+", error = ERROR)));
});
test!(bad3 {
proxy = true
"#);
assert_that(foo.cargo_process("publish").arg("-v"),
- execs().with_status(101).with_stderr("\
-invalid configuration for key `http.proxy`
+ execs().with_status(101).with_stderr(&format!("\
+{error} invalid configuration for key `http.proxy`
expected a string, but found a boolean in [..]config
-"));
+",
+ error = ERROR)));
});
test!(bad4 {
name = false
"#);
assert_that(foo.cargo_process("new").arg("-v").arg("foo"),
- execs().with_status(101).with_stderr("\
-Failed to create project `foo` at `[..]`
+ execs().with_status(101).with_stderr(&format!("\
+{error} Failed to create project `foo` at `[..]`
Caused by:
invalid configuration for key `cargo-new.name`
expected a string, but found a boolean in [..]config
-"));
+",
+ error = ERROR)));
});
test!(bad5 {
foo.build();
assert_that(foo.cargo("new")
.arg("-v").arg("foo").cwd(&foo.root().join("foo")),
- execs().with_status(101).with_stderr("\
-Couldn't load Cargo configuration
+ execs().with_status(101).with_stderr(&format!("\
+{error} Couldn't load Cargo configuration
Caused by:
failed to merge key `foo` between files:
Caused by:
expected integer, but found string
-"));
+",
+ error = ERROR)));
});
test!(bad_cargo_config_jobs {
jobs = -1
"#);
assert_that(foo.cargo_process("build").arg("-v"),
- execs().with_status(101).with_stderr("\
-build.jobs must be positive, but found -1 in [..]
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} build.jobs must be positive, but found -1 in [..]
+",
+ error = ERROR)));
});
test!(default_cargo_config_jobs {
.file("src/lib.rs", "");
assert_that(foo.cargo_process("build").arg("-v"),
- execs().with_status(101).with_stderr("\
-Couldn't load Cargo configuration
+ execs().with_status(101).with_stderr(&format!("\
+{error} Couldn't load Cargo configuration
Caused by:
could not parse TOML configuration in `[..]config`
could not parse input as TOML
[..]config:1:2 expected `=`, but found eof
-"));
+",
+ error = ERROR)));
});
test!(bad_cargo_lock {
.file("src/lib.rs", "");
assert_that(foo.cargo_process("build").arg("-v"),
- execs().with_status(101).with_stderr("\
-failed to parse lock file at: [..]Cargo.lock
+ execs().with_status(101).with_stderr(&format!("\
+{error} failed to parse lock file at: [..]Cargo.lock
Caused by:
expected a section for the key `root`
-"));
+",
+ error = ERROR)));
});
test!(bad_git_dependency {
.file("src/lib.rs", "");
assert_that(foo.cargo_process("build").arg("-v"),
- execs().with_status(101).with_stderr("\
-Unable to update file:///
+ execs().with_status(101).with_stderr(&format!("\
+{error} Unable to update file:///
Caused by:
failed to clone into: [..]
Caused by:
[[..]] 'file:///' is not a valid local file URI
-"));
+",
+ error = ERROR)));
});
test!(bad_crate_type {
.file("src/lib.rs", "");
assert_that(foo.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-failed to parse manifest at `[..]`
+ execs().with_status(101).with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
could not parse input as TOML
Cargo.toml:[..]
-"));
+",
+ error = ERROR)));
});
test!(duplicate_binary_names {
.file("b.rs", r#"fn main() -> () {}"#);
assert_that(foo.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-failed to parse manifest at `[..]`
+ execs().with_status(101).with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
found duplicate binary name e, but all binary targets must have a unique name
-"));
+",
+ error = ERROR)));
});
test!(duplicate_example_names {
.file("examples/ex2.rs", r#"fn main () -> () {}"#);
assert_that(foo.cargo_process("build").arg("--example").arg("ex"),
- execs().with_status(101).with_stderr("\
-failed to parse manifest at `[..]`
+ execs().with_status(101).with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
found duplicate example name ex, but all binary targets must have a unique name
-"));
+",
+ error = ERROR)));
});
test!(duplicate_bench_names {
.file("benches/ex2.rs", r#"fn main () {}"#);
assert_that(foo.cargo_process("bench"),
- execs().with_status(101).with_stderr("\
-failed to parse manifest at `[..]`
+ execs().with_status(101).with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
found duplicate bench name ex, but all binary targets must have a unique name
-"));
+",
+ error = ERROR)));
});
test!(unused_keys {
-use support::{project, execs, main_file, basic_bin_manifest};
+use support::{project, execs, main_file, basic_bin_manifest, ERROR};
use hamcrest::{assert_that};
fn setup() {}
.arg("--manifest-path").arg(manifest_path_argument)
.cwd(p.root().parent().unwrap()),
execs().with_status(101)
- .with_stderr("the manifest-path must be a path to a Cargo.toml file"));
+ .with_stderr(&format!("{error} the manifest-path must be a path \
+ to a Cargo.toml file",
+ error = ERROR)));
}
#[allow(deprecated)] // connect => join in 1.3
.cwd(p.root().parent().unwrap()),
execs().with_status(101)
.with_stderr(
- format!("manifest path `{}` does not exist", expected_path)
+ format!("{error} manifest path `{}` does not exist",
+ expected_path, error = ERROR)
));
}
use cargo_process;
use support::paths;
-use support::{execs, project, mkdir_recursive, ProjectBuilder};
+use support::{execs, project, mkdir_recursive, ProjectBuilder, ERROR};
use hamcrest::{assert_that};
fn setup() {
assert_that(pr,
execs().with_status(101)
- .with_stderr("no such subcommand
+ .with_stderr(&format!("{error} no such subcommand
<tab>Did you mean `build`?
-"));
+",
+error = ERROR)));
});
// if a subcommand is more than 3 edit distance away, we don't make a suggestion
assert_that(pr,
execs().with_status(101)
- .with_stderr("no such subcommand
-"));
+ .with_stderr(&format!("{error} no such subcommand
+",
+error = ERROR)));
});
test!(override_cargo_home {
use bufstream::BufStream;
use git2;
-use support::{project, execs, UPDATING};
+use support::{project, execs, UPDATING, ERROR};
use support::paths;
use hamcrest::assert_that;
addr = addr,
))
.with_stderr(&format!("\
-Unable to update http://{addr}/foo/bar
+{error} Unable to update http://{addr}/foo/bar
Caused by:
failed to clone into: [..]
To learn more, run the command again with --verbose.
",
- addr = addr)));
+ addr = addr,
+ error = ERROR)));
t.join().ok().unwrap();
});
addr = addr,
))
.with_stderr(&format!("\
-Unable to update https://{addr}/foo/bar
+{error} Unable to update https://{addr}/foo/bar
Caused by:
failed to clone into: [..]
{errmsg}
",
addr = addr,
+ error = ERROR,
errmsg = if cfg!(windows) {
"[[..]] failed to send request: [..]\n"
} else if cfg!(target_os = "macos") {
addr = addr,
))
.with_stderr(&format!("\
-Unable to update ssh://{addr}/foo/bar
+{error} Unable to update ssh://{addr}/foo/bar
Caused by:
failed to clone into: [..]
Caused by:
[[..]] Failed to start SSH session: Failed getting banner
",
- addr = addr)));
+ addr = addr,
+ error = ERROR)));
t.join().ok().unwrap();
});
use std::path::MAIN_SEPARATOR as SEP;
use support::{basic_bin_manifest, execs, project, ProjectBuilder};
-use support::{COMPILING, RUNNING};
+use support::{COMPILING, RUNNING, ERROR};
use hamcrest::{assert_that};
fn setup() {
assert_that(p.cargo_process("build").arg("--lib"),
execs().with_status(101)
- .with_stderr("no library targets found"));
+ .with_stderr(&format!("{error} no library targets found", error = ERROR)));
});
test!(build_with_relative_cargo_home_path {
use cargo::util::{Cfg, CfgExpr};
use hamcrest::assert_that;
-use support::{project, execs, COMPILING, UPDATING, DOWNLOADING};
+use support::{project, execs, COMPILING, UPDATING, DOWNLOADING, ERROR};
use support::registry::Package;
macro_rules! c {
.file("src/lib.rs", "");
assert_that(p.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-failed to parse manifest at `[..]`
+ execs().with_status(101).with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
failed to parse `4` as a cfg expression
Caused by:
unexpected character in cfg `4`, [..]
-"));
+",
+error = ERROR)));
});
test!(bad_target_spec2 {
.file("src/lib.rs", "");
assert_that(p.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-failed to parse manifest at `[..]`
+ execs().with_status(101).with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
failed to parse `foo =` as a cfg expression
Caused by:
expected a string, found nothing
-"));
+",
+error = ERROR)));
});
test!(multiple_match_ok {
use tempdir::TempDir;
use support::{project, execs, main_file, basic_bin_manifest};
-use support::{COMPILING, RUNNING, ProjectBuilder};
+use support::{COMPILING, RUNNING, ProjectBuilder, ERROR};
use hamcrest::{assert_that, existing_file, is_not};
use support::paths::{CargoPathExt,root};
use cargo::util::process;
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
no `package` or `project` section found.
-"))
+",
+error = ERROR)))
});
test!(cargo_compile_with_invalid_manifest2 {
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
could not parse input as TOML
Cargo.toml:3:19-3:20 expected a value
-"))
+",
+error = ERROR)))
});
test!(cargo_compile_with_invalid_manifest3 {
.arg("src/Cargo.toml"),
execs()
.with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
could not parse input as TOML\n\
-src[..]Cargo.toml:1:5-1:6 expected a value\n\n"))
+src[..]Cargo.toml:1:5-1:6 expected a value\n\n",
+error = ERROR)))
});
test!(cargo_compile_with_invalid_version {
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
cannot parse '1.0' as a semver for the key `project.version`
-"))
+",
+error = ERROR)))
});
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
package name cannot be an empty string.
-"))
+",
+error = ERROR)))
});
test!(cargo_compile_with_invalid_bin_target_name {
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
binary target names cannot be empty.
-"))
+",
+error = ERROR)))
});
test!(cargo_compile_with_forbidden_bin_target_name {
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
the binary target name `build` is forbidden
-"))
+",
+error = ERROR)))
});
test!(cargo_compile_with_invalid_lib_target_name {
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
library target names cannot be empty.
-"))
+",
+error = ERROR)))
});
test!(cargo_compile_without_manifest {
assert_that(p.cargo_process("build"),
execs().with_status(101)
- .with_stderr("\
-could not find `Cargo.toml` in `[..]` or any parent directory
-"));
+ .with_stderr(&format!("\
+{error} could not find `Cargo.toml` in `[..]` or any parent directory
+",
+error = ERROR)));
});
test!(cargo_compile_with_invalid_code {
src[..]foo.rs:1 invalid rust code!
^~~~~~~
")
- .with_stderr_contains("\
-Could not compile `foo`.
+ .with_stderr_contains(format!("\
+{error} Could not compile `foo`.
-To learn more, run the command again with --verbose.\n"));
+To learn more, run the command again with --verbose.\n", error = ERROR)));
assert_that(&p.root().join("Cargo.lock"), existing_file());
});
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(&format!(
-r#"no matching package named `notquitebar` found (required by `foo`)
+r#"{error} no matching package named `notquitebar` found (required by `foo`)
location searched: {proj_dir}/bar
version required: *
-"#, proj_dir = p.url())));
+"#, error = ERROR, proj_dir = p.url())));
});
test!(compile_path_dep_then_change_version {
"#).unwrap();
assert_that(p.cargo("build"),
- execs().with_status(101).with_stderr("\
-no matching package named `bar` found (required by `foo`)
+ execs().with_status(101).with_stderr(&format!("\
+{error} no matching package named `bar` found (required by `foo`)
location searched: [..]
version required: = 0.0.1
versions found: 0.0.2
consider running `cargo update` to update a path dependency's locked version
-"));
+",
+error = ERROR)));
});
test!(ignores_carriage_return_in_lockfile {
.file("src/test.rs", "fn main() {}");
assert_that(p.cargo_process("build"),
execs().with_status(101)
- .with_stderr("\
-cyclic package dependency: package `test v0.0.0 ([..])` depends on itself
-"));
+ .with_stderr(&format!("\
+{error} cyclic package dependency: package `test v0.0.0 ([..])` depends on itself
+",
+error = ERROR)));
});
test!(ignore_broken_symlinks {
"#);
assert_that(p.cargo_process("build"),
execs().with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]Cargo.toml`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]Cargo.toml`
Caused by:
no targets specified in the manifest
- either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present\n"));
+ either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present\n",
+error = ERROR)));
});
test!(lto_build {
this is not valid toml
"#);
assert_that(foo.cargo_process("build").arg("-v"),
- execs().with_status(101).with_stderr("\
-Couldn't load Cargo configuration
+ execs().with_status(101).with_stderr(&format!("\
+{error} Couldn't load Cargo configuration
Caused by:
could not parse TOML configuration in `[..]`
could not parse input as TOML
[..].cargo[..]config:2:20-2:21 expected `=`, but found `i`
-"));
+",
+error = ERROR)));
});
test!(cargo_platform_specific_dependency {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(101)
- .with_stderr("\
+ .with_stderr(format!("\
[..] can't find crate for `bbbbb`[..]
[..] extern crate bbbbb; [..]
[..]
error: aborting due to previous error
-Could not compile `foo`.
+{error} Could not compile `foo`.
Caused by:
[..]
-"));
+",
+error = ERROR)));
});
test!(cyclic_deps_rejected {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(101)
- .with_stderr("\
-cyclic package dependency: package `foo v0.0.1 ([..])` depends on itself
-"));
+ .with_stderr(&format!("\
+{error} cyclic package dependency: package `foo v0.0.1 ([..])` depends on itself
+",
+error = ERROR)));
});
test!(predictable_filenames {
assert_that(p.cargo("build")
.env("RUSTC", "rustc-that-does-not-exist").arg("-v"),
execs().with_status(101)
- .with_stderr("\
-Could not execute process `rustc-that-does-not-exist -vV` ([..])
+ .with_stderr(&format!("\
+{error} Could not execute process `rustc-that-does-not-exist -vV` ([..])
Caused by:
[..]
-"));
+",
+error = ERROR)));
assert_that(&p.bin("a"), is_not(existing_file()));
});
p.build();
assert_that(p.cargo_process("build").arg("-p").arg("notAValidDep"),
- execs().with_status(101).with_stderr(
- "could not find package matching spec `notAValidDep`".to_string()));
+ execs().with_status(101).with_stderr(&format!(
+ "{error} could not find package matching spec `notAValidDep`", error = ERROR)));
assert_that(p.cargo_process("build").arg("-p").arg("d1").arg("-p").arg("notAValidDep"),
- execs().with_status(101).with_stderr(
- "could not find package matching spec `notAValidDep`".to_string()));
+ execs().with_status(101).with_stderr(&format!(
+ "{error} could not find package matching spec `notAValidDep`", error = ERROR)));
});
use std::io::prelude::*;
use support::{project, execs};
-use support::{COMPILING, RUNNING, DOCTEST, FRESH, DOCUMENTING};
+use support::{COMPILING, RUNNING, DOCTEST, FRESH, DOCUMENTING, ERROR};
use support::paths::CargoPathExt;
use hamcrest::{assert_that, existing_file, existing_dir};
",
url = p.url(), compiling = COMPILING, running = RUNNING))
.with_stderr(&format!("\
-failed to run custom build command for `foo v0.5.0 ({})`
+{error} failed to run custom build command for `foo v0.5.0 ({})`
Process didn't exit successfully: `[..]build[..]build-script-build[..]` \
(exit code: 101)",
-p.url())));
+p.url(), error = ERROR)));
});
test!(custom_build_env_vars {
assert_that(p.cargo_process("build"),
execs().with_status(101)
.with_stderr(&format!("\
-Only `-l` and `-L` flags are allowed in build script of `foo v0.5.0 ({})`: \
+{error} Only `-l` and `-L` flags are allowed in build script of `foo v0.5.0 ({})`: \
`-aaa -bbb`",
-p.url())));
+p.url(), error = ERROR)));
});
/*
assert_that(p.cargo_process("build"),
execs().with_status(101)
- .with_stderr("\
-package `foo v0.5.0 (file://[..])` specifies that it links to `a` but does \
+ .with_stderr(&format!("\
+{error} package `foo v0.5.0 (file://[..])` specifies that it links to `a` but does \
not have a custom build script
-"));
+",
+ error = ERROR)));
});
test!(links_duplicates {
assert_that(p.cargo_process("build"),
execs().with_status(101)
- .with_stderr("\
-native library `a` is being linked to by more than one package, and can only be \
+ .with_stderr(&format!("\
+{error} native library `a` is being linked to by more than one package, and can only be \
linked to by one package
[..] v0.5.0 (file://[..])
[..] v0.5.0 (file://[..])
-"));
+",
+ error = ERROR)));
});
test!(overrides_and_links {
assert_that(p.cargo_process("build").arg("-v").arg("--target").arg(&target),
execs().with_status(101)
- .with_stderr("\
+ .with_stderr(&format!("\
[..]lib.rs[..] error: can't find crate for `aaaaa`[..]
[..]lib.rs[..] extern crate aaaaa;
[..] ^~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
-Could not compile `foo`.
+{error} Could not compile `foo`.
Caused by:
Process didn't exit successfully: [..]
-"));
+",
+ error = ERROR)));
});
test!(build_cmd_with_a_build_cmd {
.file("build.rs", r#"fn main() {}"#);
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
no targets specified in the manifest
- either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present"));
+ either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present",
+ error = ERROR)));
});
test!(shared_dep_with_a_build_script {
use git2;
use support::{git, project, execs, main_file, path2url};
-use support::{COMPILING, UPDATING, RUNNING};
+use support::{COMPILING, UPDATING, RUNNING, ERROR};
use support::paths::{self, CargoPathExt};
use hamcrest::{assert_that,existing_file};
use cargo::util::process;
execs()
.with_stdout("")
.with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
invalid url `{}`: relative URL without a base
-", url)));
+", url, error = ERROR)));
});
test!(two_revs_same_deps {
assert_that(p.cargo("update")
.arg("-p").arg("bar")
.arg("--precise").arg("0.1.2"),
- execs().with_status(101).with_stderr("\
-Unable to update [..]
+ execs().with_status(101).with_stderr(&format!("\
+{error} Unable to update [..]
To learn more, run the command again with --verbose.
-"));
+",
+error = ERROR)));
// Specifying a precise rev to the old rev shouldn't actually update
// anything because we already have the rev in the db.
assert_that(p.cargo("update")
.arg("-p").arg("foo"),
execs().with_status(101)
- .with_stderr("\
-There are multiple `foo` packages in your project, and the specification `foo` \
+ .with_stderr(&format!("\
+{error} There are multiple `foo` packages in your project, and the specification `foo` \
is ambiguous.
Please re-run this command with `-p <spec>` where `<spec>` is one of the \
following:
foo:0.[..].0
foo:0.[..].0
-"));
+",
+error = ERROR)));
});
test!(update_one_dep_in_repo_with_many_deps {
use std::io::prelude::*;
use support::{project, execs, main_file};
-use support::{COMPILING, RUNNING};
+use support::{COMPILING, RUNNING, ERROR};
use support::paths::{self, CargoPathExt};
use hamcrest::{assert_that, existing_file};
use cargo::util::process;
assert_that(p.cargo_process("build"),
execs().with_status(101)
- .with_stderr("\
-Unable to update file://[..]
+ .with_stderr(&format!("\
+{error} Unable to update file://[..]
Caused by:
failed to read `[..]bar[..]Cargo.toml`
Caused by:
[..] (os error [..])
-"));
+",
+error = ERROR)));
});
p.build();
assert_that(p.cargo("build"),
execs().with_status(101)
- .with_stderr("\
-failed to update path override `[..]../whoa-this-does-not-exist` \
+ .with_stderr(format!("\
+{error} failed to update path override `[..]../whoa-this-does-not-exist` \
(defined in `[..]`)
Caused by:
Caused by:
[..] (os error [..])
-"));
+", error = ERROR)));
});
use std::env;
use support::{project, execs, basic_bin_manifest};
-use support::{RUNNING, COMPILING, DOCTEST};
+use support::{RUNNING, COMPILING, DOCTEST, ERROR};
use hamcrest::{assert_that, existing_file};
use cargo::util::process;
assert_that(p.cargo_process("build").arg("-v").arg("--target").arg(&target),
execs().with_status(101)
- .with_stderr("\
+ .with_stderr(format!("\
[..] error: can't find crate for `d2`[..]
[..] extern crate d2;
[..]
error: aborting due to previous error
-Could not compile `d1`.
+{error} Could not compile `d1`.
Caused by:
[..]
-"));
+", error = ERROR)));
});
test!(platform_specific_variables_reflected_in_build_scripts {
use std::fs;
use support::{project, execs, path2url};
-use support::{COMPILING, DOCUMENTING, RUNNING};
+use support::{COMPILING, DOCUMENTING, RUNNING, ERROR};
use hamcrest::{assert_that, existing_file, existing_dir, is_not};
fn setup() {
assert_that(p.cargo_process("doc"),
execs().with_status(101)
- .with_stderr("\
-cannot document a package where a library and a binary have the same name. \
+ .with_stderr(&format!("\
+{error} cannot document a package where a library and a binary have the same name. \
Consider renaming one or marking the target as `doc = false`
-"));
+",
+error = ERROR)));
});
test!(doc_dash_p {
use std::io::prelude::*;
use support::{project, execs};
-use support::{COMPILING, FRESH};
+use support::{COMPILING, FRESH, ERROR};
use support::paths::CargoPathExt;
use hamcrest::assert_that;
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
Feature `bar` includes `baz` which is neither a dependency nor another feature
-")));
+",
+error = ERROR)));
});
test!(invalid2 {
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
Features and dependencies cannot have the same name: `bar`
-")));
+",
+error = ERROR)));
});
test!(invalid3 {
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
Feature `bar` depends on `baz` which is not an optional dependency.
Consider adding `optional = true` to the dependency
-")));
+",
+error = ERROR)));
});
test!(invalid4 {
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(&format!("\
-Package `bar v0.0.1 ([..])` does not have these features: `bar`
-")));
+{error} Package `bar v0.0.1 ([..])` does not have these features: `bar`
+",
+error = ERROR)));
let p = p.file("Cargo.toml", r#"
[project]
assert_that(p.cargo_process("build").arg("--features").arg("test"),
execs().with_status(101).with_stderr(&format!("\
-Package `foo v0.0.1 ([..])` does not have these features: `test`
-")));
+{error} Package `foo v0.0.1 ([..])` does not have these features: `test`
+",
+error = ERROR)));
});
test!(invalid5 {
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
Dev-dependencies are not allowed to be optional: `bar`
-")));
+",
+error = ERROR)));
});
test!(invalid6 {
assert_that(p.cargo_process("build").arg("--features").arg("foo"),
execs().with_status(101).with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
Feature `foo` requires `bar` which is not an optional dependency
-")));
+",
+error = ERROR)));
});
test!(invalid7 {
assert_that(p.cargo_process("build").arg("--features").arg("foo"),
execs().with_status(101).with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
Feature `foo` requires `bar` which is not an optional dependency
-")));
+",
+error = ERROR)));
});
test!(invalid8 {
assert_that(p.cargo_process("build").arg("--features").arg("foo"),
execs().with_status(101).with_stderr(&format!("\
-features in dependencies cannot enable features in other dependencies: `foo/bar`
-")));
+{error} features in dependencies cannot enable features in other dependencies: `foo/bar`
+",
+error = ERROR)));
});
test!(no_feature_doesnt_build {
.file("src/main.rs", "");
assert_that(p.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-Cyclic feature dependency: feature `default` depends on itself
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} Cyclic feature dependency: feature `default` depends on itself
+",
+error = ERROR)));
});
test!(cyclic_feature2 {
.file("src/main.rs", "");
assert_that(p.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-Cyclic feature dependency: feature `[..]` depends on itself
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} Cyclic feature dependency: feature `[..]` depends on itself
+",
+error = ERROR)));
});
test!(groups_on_groups_on_groups {
use std::io::prelude::*;
use std::env;
use tempdir::TempDir;
-use support::{execs, paths, cargo_dir};
+use support::{execs, paths, cargo_dir, ERROR};
use hamcrest::{assert_that, existing_file, existing_dir, is_not};
use cargo::util::{process, ProcessBuilder};
fn bin_already_exists(explicit: bool, rellocation: &str) {
let path = paths::root().join("foo");
fs::create_dir_all(&path.join("src")).unwrap();
-
+
let sourcefile_path = path.join(rellocation);
-
+
let content = br#"
fn main() {
println!("Hello, world 2!");
}
"#;
-
+
File::create(&sourcefile_path).unwrap().write_all(content).unwrap();
-
+
if explicit {
assert_that(cargo_process("init").arg("--bin").arg("--vcs").arg("none")
.env("USER", "foo").cwd(&path),
assert_that(&paths::root().join("foo/Cargo.toml"), existing_file());
assert_that(&paths::root().join("foo/src/lib.rs"), is_not(existing_file()));
-
+
// Check that our file is not overwritten
let mut new_content = Vec::new();
File::open(&sourcefile_path).unwrap().read_to_end(&mut new_content).unwrap();
test!(confused_by_multiple_lib_files {
let path = paths::root().join("foo");
fs::create_dir_all(&path.join("src")).unwrap();
-
+
let sourcefile_path1 = path.join("src/lib.rs");
-
+
File::create(&sourcefile_path1).unwrap().write_all(br#"
fn qqq () {
println!("Hello, world 2!");
}
"#).unwrap();
-
+
let sourcefile_path2 = path.join("lib.rs");
-
+
File::create(&sourcefile_path2).unwrap().write_all(br#"
fn qqq () {
println!("Hello, world 3!");
}
"#).unwrap();
-
+
assert_that(cargo_process("init").arg("--vcs").arg("none")
.env("USER", "foo").cwd(&path),
- execs().with_status(101).with_stderr("\
-cannot have a project with multiple libraries, found both `src/lib.rs` and `lib.rs`
-"));
-
+ execs().with_status(101).with_stderr(&format!("\
+{error} cannot have a project with multiple libraries, found both `src/lib.rs` and `lib.rs`
+",
+error = ERROR)));
+
assert_that(&paths::root().join("foo/Cargo.toml"), is_not(existing_file()));
});
test!(multibin_project_name_clash {
let path = paths::root().join("foo");
fs::create_dir(&path).unwrap();
-
+
let sourcefile_path1 = path.join("foo.rs");
-
+
File::create(&sourcefile_path1).unwrap().write_all(br#"
fn main () {
println!("Hello, world 2!");
}
"#).unwrap();
-
+
let sourcefile_path2 = path.join("main.rs");
-
+
File::create(&sourcefile_path2).unwrap().write_all(br#"
fn main () {
println!("Hello, world 3!");
}
"#).unwrap();
-
+
assert_that(cargo_process("init").arg("--vcs").arg("none")
.env("USER", "foo").cwd(&path),
- execs().with_status(101).with_stderr("\
-multiple possible binary sources found:
+ execs().with_status(101).with_stderr(&format!("\
+{error} multiple possible binary sources found:
main.rs
foo.rs
cannot automatically generate Cargo.toml as the main target would be ambiguous
-"));
-
+",
+error = ERROR)));
+
assert_that(&paths::root().join("foo/Cargo.toml"), is_not(existing_file()));
});
fn lib_already_exists(rellocation: &str) {
let path = paths::root().join("foo");
fs::create_dir_all(&path.join("src")).unwrap();
-
+
let sourcefile_path = path.join(rellocation);
-
+
let content = br#"
pub fn qqq() {}
"#;
-
+
File::create(&sourcefile_path).unwrap().write_all(content).unwrap();
-
+
assert_that(cargo_process("init").arg("--vcs").arg("none")
.env("USER", "foo").cwd(&path),
execs().with_status(0));
assert_that(&paths::root().join("foo/Cargo.toml"), existing_file());
assert_that(&paths::root().join("foo/src/main.rs"), is_not(existing_file()));
-
+
// Check that our file is not overwritten
let mut new_content = Vec::new();
File::open(&sourcefile_path).unwrap().read_to_end(&mut new_content).unwrap();
fs::create_dir_all(&foo).unwrap();
assert_that(cargo_process("init").cwd(foo.clone())
.env("USER", "foo"),
- execs().with_status(101).with_stderr("\
-Invalid character `.` in crate name: `foo.bar`
+ execs().with_status(101).with_stderr(&format!("\
+{error} Invalid character `.` in crate name: `foo.bar`
use --name to override crate name
-"));
+",
+error = ERROR)));
assert_that(&foo.join("Cargo.toml"), is_not(existing_file()));
});
test!(git_autodetect {
fs::create_dir(&paths::root().join(".git")).unwrap();
-
+
assert_that(cargo_process("init")
.env("USER", "foo"),
execs().with_status(0));
-
+
assert_that(&paths::root().join("Cargo.toml"), existing_file());
assert_that(&paths::root().join("src/lib.rs"), existing_file());
test!(mercurial_autodetect {
fs::create_dir(&paths::root().join(".hg")).unwrap();
-
+
assert_that(cargo_process("init")
.env("USER", "foo"),
execs().with_status(0));
-
+
assert_that(&paths::root().join("Cargo.toml"), existing_file());
assert_that(&paths::root().join("src/lib.rs"), existing_file());
test!(gitignore_appended_not_replaced {
fs::create_dir(&paths::root().join(".git")).unwrap();
-
+
File::create(&paths::root().join(".gitignore")).unwrap().write_all(b"qqqqqq\n").unwrap();
-
+
assert_that(cargo_process("init")
.env("USER", "foo"),
execs().with_status(0));
-
+
assert_that(&paths::root().join("Cargo.toml"), existing_file());
assert_that(&paths::root().join("src/lib.rs"), existing_file());
assert_that(&paths::root().join(".git"), existing_dir());
assert_that(&paths::root().join(".gitignore"), existing_file());
-
+
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"qqqqqq"#));
test!(cargo_lock_gitignored_if_lib1 {
fs::create_dir(&paths::root().join(".git")).unwrap();
-
+
assert_that(cargo_process("init").arg("--vcs").arg("git")
.env("USER", "foo"),
execs().with_status(0));
-
+
assert_that(&paths::root().join(".gitignore"), existing_file());
-
+
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"Cargo.lock"#));
test!(cargo_lock_gitignored_if_lib2 {
fs::create_dir(&paths::root().join(".git")).unwrap();
-
+
File::create(&paths::root().join("lib.rs")).unwrap().write_all(br#""#).unwrap();
assert_that(cargo_process("init").arg("--vcs").arg("git")
.env("USER", "foo"),
execs().with_status(0));
-
+
assert_that(&paths::root().join(".gitignore"), existing_file());
-
+
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"Cargo.lock"#));
test!(cargo_lock_not_gitignored_if_bin1 {
fs::create_dir(&paths::root().join(".git")).unwrap();
-
+
assert_that(cargo_process("init").arg("--vcs").arg("git")
.arg("--bin")
.env("USER", "foo"),
execs().with_status(0));
-
+
assert_that(&paths::root().join(".gitignore"), existing_file());
-
+
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(!contents.contains(r#"Cargo.lock"#));
test!(cargo_lock_not_gitignored_if_bin2 {
fs::create_dir(&paths::root().join(".git")).unwrap();
-
+
File::create(&paths::root().join("main.rs")).unwrap().write_all(br#""#).unwrap();
assert_that(cargo_process("init").arg("--vcs").arg("git")
.env("USER", "foo"),
execs().with_status(0));
-
+
assert_that(&paths::root().join(".gitignore"), existing_file());
-
+
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(!contents.contains(r#"Cargo.lock"#));
test!(unknown_flags {
assert_that(cargo_process("init").arg("foo").arg("--flag"),
execs().with_status(1)
- .with_stderr("\
-Unknown flag: '--flag'
+ .with_stderr(&format!("\
+{error} Unknown flag: '--flag'
Usage:
cargo init [options] [<path>]
cargo init -h | --help
-"));
+",
+error = ERROR)));
});
#[cfg(not(windows))]
test!(no_filename {
assert_that(cargo_process("init").arg("/"),
execs().with_status(101)
- .with_stderr("\
-cannot auto-detect project name from path \"/\" ; use --name to override
-"));
+ .with_stderr(&format!("\
+{error} cannot auto-detect project name from path \"/\" ; use --name to override
+",
+error = ERROR)));
});
use hamcrest::{assert_that, existing_file, is_not, Matcher, MatchResult};
use support::{project, execs};
-use support::{UPDATING, DOWNLOADING, COMPILING, INSTALLING, REMOVING};
+use support::{UPDATING, DOWNLOADING, COMPILING, INSTALLING, REMOVING, ERROR};
use support::paths;
use support::registry::Package;
use support::git;
test!(missing {
pkg("foo", "0.0.1");
assert_that(cargo_process("install").arg("bar"),
- execs().with_status(101).with_stderr("\
-could not find `bar` in `registry file://[..]`
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} could not find `bar` in `registry file://[..]`
+",
+error = ERROR)));
});
test!(bad_version {
pkg("foo", "0.0.1");
assert_that(cargo_process("install").arg("foo").arg("--vers=0.2.0"),
- execs().with_status(101).with_stderr("\
-could not find `foo` in `registry file://[..]` with version `0.2.0`
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} could not find `foo` in `registry file://[..]` with version `0.2.0`
+",
+error = ERROR)));
});
test!(no_crate {
assert_that(cargo_process("install"),
- execs().with_status(101).with_stderr("\
-`[..]` is not a crate root; specify a crate to install [..]
+ execs().with_status(101).with_stderr(&format!("\
+{error} `[..]` is not a crate root; specify a crate to install [..]
Caused by:
failed to read `[..]Cargo.toml`
Caused by:
[..] (os error [..])
-"));
+",
+error = ERROR)));
});
test!(install_location_precedence {
execs().with_status(0));
assert_that(cargo_home(), has_installed_exe("foo"));
assert_that(cargo_process("install").arg("--path").arg(".").cwd(p.root()),
- execs().with_status(101).with_stderr("\
-binary `foo[..]` already exists in destination as part of `foo v0.1.0 [..]`
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} binary `foo[..]` already exists in destination as part of `foo v0.1.0 [..]`
+",
+error = ERROR)));
});
test!(multiple_crates_error {
p.build();
assert_that(cargo_process("install").arg("--git").arg(p.url().to_string()),
- execs().with_status(101).with_stderr("\
-multiple packages with binaries found: bar, foo
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} multiple packages with binaries found: bar, foo
+",
+error = ERROR)));
});
test!(multiple_crates_select {
p.build();
assert_that(cargo_process("install").arg("--path").arg(p.root()),
- execs().with_status(101).with_stderr("\
-no packages found with binaries or examples
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} no packages found with binaries or examples
+",
+error = ERROR)));
});
test!(no_binaries {
p.build();
assert_that(cargo_process("install").arg("--path").arg(p.root()).arg("foo"),
- execs().with_status(101).with_stderr("\
-specified package has no binaries
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} specified package has no binaries
+",
+error = ERROR)));
});
test!(examples {
assert_that(cargo_process("install").arg("--path").arg(p.root()),
execs().with_status(0));
assert_that(cargo_process("install").arg("--path").arg(p.root()),
- execs().with_status(101).with_stderr("\
-binary `foo[..]` already exists in destination as part of `foo v0.1.0 ([..])`
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} binary `foo[..]` already exists in destination as part of `foo v0.1.0 ([..])`
+",
+error = ERROR)));
});
test!(compile_failure {
p.build();
assert_that(cargo_process("install").arg("--path").arg(p.root()),
- execs().with_status(101).with_stderr("\
+ execs().with_status(101).with_stderr(&format!("\
error: main function not found
error: aborting due to previous error
-failed to compile `foo v0.1.0 (file://[..])`, intermediate artifacts can be \
+{error} failed to compile `foo v0.1.0 (file://[..])`, intermediate artifacts can be \
found at `[..]target`
Caused by:
Could not compile `foo`.
To learn more, run the command again with --verbose.
-"));
+",
+error = ERROR)));
});
test!(git_repo {
test!(uninstall_pkg_does_not_exist {
assert_that(cargo_process("uninstall").arg("foo"),
- execs().with_status(101).with_stderr("\
-package id specification `foo` matched no packages
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} package id specification `foo` matched no packages
+",
+error = ERROR)));
});
test!(uninstall_bin_does_not_exist {
assert_that(cargo_process("install").arg("foo"),
execs().with_status(0));
assert_that(cargo_process("uninstall").arg("foo").arg("--bin=bar"),
- execs().with_status(101).with_stderr("\
-binary `bar[..]` not installed as part of `foo v0.0.1 ([..])`
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} binary `bar[..]` not installed as part of `foo v0.0.1 ([..])`
+",
+error = ERROR)));
});
test!(uninstall_piecemeal {
assert_that(cargo_home(), is_not(has_installed_exe("foo")));
assert_that(cargo_process("uninstall").arg("foo"),
- execs().with_status(101).with_stderr("\
-package id specification `foo` matched no packages
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} package id specification `foo` matched no packages
+",
+error = ERROR)));
});
test!(subcommand_works_out_of_the_box {
assert_that(cargo_process("fail"),
execs().with_status(101).with_stderr_contains("\
thread '<main>' panicked at 'explicit panic', [..]
-").with_stderr_contains("\
-third party subcommand `cargo-fail[..]` exited unsuccessfully
+").with_stderr_contains(format!("\
+{error} third party subcommand `cargo-fail[..]` exited unsuccessfully
To learn more, run the command again with --verbose.
-"));
+",
+error = ERROR)));
});
test!(git_with_lockfile {
use hamcrest::assert_that;
use support::registry::Package;
-use support::{project, execs, basic_bin_manifest, main_file};
+use support::{project, execs, basic_bin_manifest, main_file, ERROR};
fn setup() {}
.file("Cargo.toml", "");
assert_that(p.cargo_process("metadata"), execs().with_status(101)
- .with_stderr("\
-failed to parse manifest at `[..]`
+ .with_stderr(&format!("\
+{error} failed to parse manifest at `[..]`
Caused by:
- no `package` or `project` section found."))
+ no `package` or `project` section found.",
+ error = ERROR)))
});
const MANIFEST_OUTPUT: &'static str=
.arg("--manifest-path").arg("foo")
.cwd(p.root().parent().unwrap()),
execs().with_status(101)
- .with_stderr("the manifest-path must be a path to a Cargo.toml file"));
+ .with_stderr(&format!("{error} the manifest-path must be \
+ a path to a Cargo.toml file",
+ error = ERROR)));
});
test!(cargo_metadata_no_deps_path_to_cargo_toml_parent_absolute {
.arg("--manifest-path").arg(p.root())
.cwd(p.root().parent().unwrap()),
execs().with_status(101)
- .with_stderr("the manifest-path must be a path to a Cargo.toml file"));
+ .with_stderr(&format!("{error} the manifest-path must be \
+ a path to a Cargo.toml file",
+ error = ERROR)));
});
test!(cargo_metadata_no_deps_cwd {
.arg("--format-version").arg("2")
.cwd(p.root()),
execs().with_status(101)
- .with_stderr("metadata version 2 not supported, only 1 is currently supported"));
+ .with_stderr(&format!("{error} metadata version 2 not supported, only 1 is currently supported",
+ error = ERROR)));
});
use std::env;
use tempdir::TempDir;
-use support::{execs, paths};
+use support::{execs, paths, ERROR};
use support::paths::CargoPathExt;
use hamcrest::{assert_that, existing_file, existing_dir, is_not};
test!(no_argument {
assert_that(cargo_process("new"),
execs().with_status(1)
- .with_stderr("\
-Invalid arguments.
+ .with_stderr(&format!("\
+{error} Invalid arguments.
Usage:
cargo new [options] <path>
cargo new -h | --help
-"));
+",
+error = ERROR)));
});
test!(existing {
fs::create_dir(&dst).unwrap();
assert_that(cargo_process("new").arg("foo"),
execs().with_status(101)
- .with_stderr(format!("destination `{}` already exists\n",
- dst.display())));
+ .with_stderr(format!("{error} destination `{}` already exists\n",
+ dst.display(), error = ERROR)));
});
test!(invalid_characters {
assert_that(cargo_process("new").arg("foo.rs"),
execs().with_status(101)
- .with_stderr("\
-Invalid character `.` in crate name: `foo.rs`
-use --name to override crate name"));
+ .with_stderr(&format!("\
+{error} Invalid character `.` in crate name: `foo.rs`
+use --name to override crate name",
+error = ERROR)));
});
test!(rust_prefix_stripped {
test!(unknown_flags {
assert_that(cargo_process("new").arg("foo").arg("--flag"),
execs().with_status(1)
- .with_stderr("\
-Unknown flag: '--flag'
+ .with_stderr(&format!("\
+{error} Unknown flag: '--flag'
Usage:
cargo new [..]
cargo new [..]
-"));
+",
+error = ERROR)));
});
#[cfg(unix)] // windows doesn't allow these characters in filenames
test!(package_weird_characters {
+
+ use support::ERROR;
let p = project("foo")
.file("Cargo.toml", r#"
[project]
.file("src/:foo", "");
assert_that(p.cargo_process("package"),
- execs().with_status(101).with_stderr("\
+ execs().with_status(101).with_stderr(format!("\
warning: [..]
-failed to prepare local package for uploading
+{error} failed to prepare local package for uploading
Caused by:
cannot package a filename with a special character `:`: src/:foo
-"));
+",
+error = ERROR)));
});
use url::Url;
use support::{project, execs};
-use support::{UPDATING, PACKAGING, UPLOADING};
+use support::{UPDATING, PACKAGING, UPLOADING, ERROR};
use support::paths;
use support::git::repo;
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("publish").arg("-v").arg("--no-verify"),
- execs().with_status(101).with_stderr("\
-all dependencies must come from the same source.
+ execs().with_status(101).with_stderr(&format!("\
+{error} all dependencies must come from the same source.
dependency `foo` comes from git://path/to/nowhere instead
-"));
+",
+error = ERROR)));
});
test!(path_dependency_no_version {
.file("bar/src/lib.rs", "");
assert_that(p.cargo_process("publish"),
- execs().with_status(101).with_stderr("\
-all path dependencies must have a version specified when publishing.
+ execs().with_status(101).with_stderr(&format!("\
+{error} all path dependencies must have a version specified when publishing.
dependency `bar` does not specify a version
-"));
+",
+error = ERROR)));
});
test!(unpublishable_crate {
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("publish"),
- execs().with_status(101).with_stderr("\
-some crates cannot be published.
+ execs().with_status(101).with_stderr(&format!("\
+{error} some crates cannot be published.
`foo` is marked as unpublishable
-"));
+",
+error = ERROR)));
});
-use support::{project, execs, main_file, basic_bin_manifest};
+use support::{project, execs, main_file, basic_bin_manifest, ERROR};
use hamcrest::{assert_that};
fn setup() {}
.arg("--manifest-path").arg("foo")
.cwd(p.root().parent().unwrap()),
execs().with_status(101)
- .with_stderr("the manifest-path must be a path to a Cargo.toml file"));
+ .with_stderr(&format!("{error} the manifest-path must be \
+ a path to a Cargo.toml file", error = ERROR)));
});
test!(cargo_read_manifest_path_to_cargo_toml_parent_absolute {
.arg("--manifest-path").arg(p.root())
.cwd(p.root().parent().unwrap()),
execs().with_status(101)
- .with_stderr("the manifest-path must be a path to a Cargo.toml file"));
+ .with_stderr(&format!("{error} the manifest-path must be \
+ a path to a Cargo.toml file", error = ERROR)));
});
test!(cargo_read_manifest_cwd {
use std::io::prelude::*;
use support::{project, execs};
-use support::{UPDATING, DOWNLOADING, COMPILING, PACKAGING, VERIFYING, ADDING, REMOVING};
+use support::{UPDATING, DOWNLOADING, COMPILING, PACKAGING, VERIFYING, ADDING, REMOVING, ERROR};
use support::paths::{self, CargoPathExt};
use support::registry::{self, Package};
use support::git;
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-no matching package named `nonexistent` found (required by `foo`)
+ execs().with_status(101).with_stderr(&format!("\
+{error} no matching package named `nonexistent` found (required by `foo`)
location searched: registry file://[..]
version required: >= 0.0.0
-"));
+",
+error = ERROR)));
});
test!(wrong_version {
Package::new("foo", "0.0.2").publish();
assert_that(p.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-no matching package named `foo` found (required by `foo`)
+ execs().with_status(101).with_stderr(&format!("\
+{error} no matching package named `foo` found (required by `foo`)
location searched: registry file://[..]
version required: >= 1.0.0
versions found: 0.0.2, 0.0.1
-"));
+",
+error = ERROR)));
Package::new("foo", "0.0.3").publish();
Package::new("foo", "0.0.4").publish();
assert_that(p.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-no matching package named `foo` found (required by `foo`)
+ execs().with_status(101).with_stderr(&format!("\
+{error} no matching package named `foo` found (required by `foo`)
location searched: registry file://[..]
version required: >= 1.0.0
versions found: 0.0.4, 0.0.3, 0.0.2, ...
-"));
+",
+error = ERROR)));
});
test!(bad_cksum {
File::create(&pkg.archive_dst()).unwrap();
assert_that(p.cargo_process("build").arg("-v"),
- execs().with_status(101).with_stderr("\
-unable to get packages from source
+ execs().with_status(101).with_stderr(&format!("\
+{error} unable to get packages from source
Caused by:
failed to download package `bad-cksum v0.0.1 (registry file://[..])` from [..]
Caused by:
failed to verify the checksum of `bad-cksum v0.0.1 (registry file://[..])`
-"));
+",
+error = ERROR)));
});
test!(update_registry {
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("build"),
- execs().with_status(101).with_stderr("\
-no matching package named `notyet` found (required by `foo`)
+ execs().with_status(101).with_stderr(&format!("\
+{error} no matching package named `notyet` found (required by `foo`)
location searched: registry file://[..]
version required: >= 0.0.0
-"));
+",
+error = ERROR)));
Package::new("notyet", "0.0.1").publish();
p.build();
assert_that(p.cargo("package").arg("-v"),
- execs().with_status(101).with_stderr("\
-failed to verify package tarball
+ execs().with_status(101).with_stderr(&format!("\
+{error} failed to verify package tarball
Caused by:
no matching package named `notyet` found (required by `foo`)
location searched: registry file://[..]
version required: ^0.0.1
-"));
+",
+error = ERROR)));
Package::new("notyet", "0.0.1").publish();
Package::new("bar", "0.0.1").dep("baz", "=0.0.2").publish();
assert_that(p.cargo("build"),
- execs().with_status(101).with_stderr("\
-no matching package named `baz` found (required by `bar`)
+ execs().with_status(101).with_stderr(&format!("\
+{error} no matching package named `baz` found (required by `bar`)
location searched: registry file://[..]
version required: = 0.0.2
versions found: 0.0.1
-"));
+",
+error = ERROR)));
});
test!(yanks_in_lockfiles_are_ok {
execs().with_status(0).with_stdout(""));
assert_that(p.cargo("update"),
- execs().with_status(101).with_stderr("\
-no matching package named `bar` found (required by `foo`)
+ execs().with_status(101).with_stderr(&format!("\
+{error} no matching package named `bar` found (required by `foo`)
location searched: registry file://[..]
version required: *
-"));
+",
+error = ERROR)));
});
test!(update_with_lockfile_if_packages_missing {
"#);
assert_that(p.cargo_process("publish").arg("-v"),
execs().with_status(101)
- .with_stderr("\
-the license file `foo` does not exist"));
+ .with_stderr(&format!("\
+{error} the license file `foo` does not exist", error = ERROR)));
});
test!(updating_a_dep {
use std::path::MAIN_SEPARATOR as SEP;
use support::{project, execs, path2url};
-use support::{COMPILING, RUNNING};
+use support::{COMPILING, RUNNING, ERROR};
use hamcrest::{assert_that, existing_file};
fn setup() {
"#);
assert_that(p.cargo_process("run").arg("-q").arg("-v"),
- execs().with_status(101).with_stderr("\
-cannot set both --verbose and --quiet
-")
- );
+ execs().with_status(101).with_stderr(&format!("\
+{error} cannot set both --verbose and --quiet
+",
+error = ERROR)));
});
test!(simple_with_args {
assert_that(p.cargo_process("run"),
execs().with_status(2)
.with_stderr(&format!("\
-Process didn't exit successfully: `target[..]foo[..]` (exit code: 2)
+{error} Process didn't exit successfully: `target[..]foo[..]` (exit code: 2)
",
- )));
+error = ERROR)));
});
test!(exit_code_verbose {
assert_that(p.cargo_process("run").arg("-v"),
execs().with_status(2)
.with_stderr(&format!("\
-Process didn't exit successfully: `target[..]foo[..]` (exit code: 2)
+{error} Process didn't exit successfully: `target[..]foo[..]` (exit code: 2)
",
- )));
+error = ERROR)));
});
test!(no_main_file {
assert_that(p.cargo_process("run"),
execs().with_status(101)
- .with_stderr("a bin target must be available \
- for `cargo run`\n"));
+ .with_stderr(&format!("{error} a bin target must be available \
+ for `cargo run`\n", error = ERROR)));
});
test!(too_many_bins {
assert_that(p.cargo_process("run"),
execs().with_status(101)
- .with_stderr("`cargo run` requires that a project only \
+ .with_stderr(&format!("{error} `cargo run` requires that a project only \
have one executable; use the `--bin` option \
- to specify which one to run\n"));
+ to specify which one to run\n", error = ERROR)));
});
test!(specify_name {
assert_that(p.cargo_process("run").arg("--bin").arg("a").arg("--example").arg("b"),
execs().with_status(101)
- .with_stderr("`cargo run` can run at most one \
+ .with_stderr(&format!("{error} `cargo run` can run at most one \
executable, but multiple were \
- specified"));
+ specified",
+ error = ERROR)));
});
test!(one_bin_multiple_examples {
use std::path::MAIN_SEPARATOR as SEP;
use support::{execs, project};
-use support::{COMPILING, RUNNING};
+use support::{COMPILING, RUNNING, ERROR};
use hamcrest::assert_that;
fn setup() {
}
-fn cargo_rustc_error() -> &'static str {
- "extra arguments to `rustc` can only be passed to one target, consider filtering\n\
- the package by passing e.g. `--lib` or `--bin NAME` to specify a single target"
+fn cargo_rustc_error() -> String {
+ format!("{error} extra arguments to `rustc` can only be passed to one target, \
+ consider filtering\nthe package by passing e.g. `--lib` or `--bin NAME` to \
+ specify a single target", error = ERROR)
}
test!(build_lib_for_foo {
.arg("--").arg("-Z").arg("unstable-options"),
execs()
.with_status(101)
- .with_stderr(cargo_rustc_error()));
+ .with_stderr(&cargo_rustc_error()));
});
test!(build_with_args_to_one_of_multiple_binaries {
.arg("--").arg("-Z").arg("unstable-options"),
execs()
.with_status(101)
- .with_stderr(cargo_rustc_error()));
+ .with_stderr(&cargo_rustc_error()));
});
test!(build_with_args_to_one_of_multiple_tests {
assert_that(foo.cargo("rustc").arg("-v").arg("-p").arg("bar")
.arg("-p").arg("baz"),
- execs().with_status(1).with_stderr("\
-Invalid arguments.
+ execs().with_status(1).with_stderr(format!("\
+{error} Invalid arguments.
Usage:
- cargo rustc [options] [--] [<opts>...]".to_string()));
+ cargo rustc [options] [--] [<opts>...]", error = ERROR)));
});
test!(rustc_with_other_profile {
use std::path::MAIN_SEPARATOR as SEP;
use support::{execs, project};
-use support::{COMPILING, RUNNING, DOCUMENTING};
+use support::{COMPILING, RUNNING, DOCUMENTING, ERROR};
use hamcrest::{assert_that};
fn setup() {
.arg("--").arg("--no-defaults"),
execs()
.with_status(101)
- .with_stderr("cannot document a package where a library and a \
+ .with_stderr(&format!("{error} cannot document a package where a library and a \
binary have the same name. Consider renaming one \
- or marking the target as `doc = false`"));
+ or marking the target as `doc = false`",
+ error = ERROR)));
});
use std::str;
use support::{project, execs, basic_bin_manifest, basic_lib_manifest};
-use support::{COMPILING, RUNNING, DOCTEST};
+use support::{COMPILING, RUNNING, DOCTEST, ERROR};
use support::paths::CargoPathExt;
use hamcrest::{assert_that, existing_file, is_not};
use cargo::util::process;
assert_that(p.cargo_process("test"),
execs().with_status(101)
.with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
- binary target bin.name is required")));
+ binary target bin.name is required",
+ error = ERROR)));
});
test!(bench_without_name {
assert_that(p.cargo_process("test"),
execs().with_status(101)
.with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
- bench target bench.name is required")));
+ bench target bench.name is required",
+ error = ERROR)));
});
test!(test_without_name {
assert_that(p.cargo_process("test"),
execs().with_status(101)
.with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
- test target test.name is required")));
+ test target test.name is required",
+ error = ERROR)));
});
test!(example_without_name {
assert_that(p.cargo_process("test"),
execs().with_status(101)
.with_stderr(&format!("\
-failed to parse manifest at `[..]`
+{error} failed to parse manifest at `[..]`
Caused by:
- example target example.name is required")));
+ example target example.name is required",
+ error = ERROR)));
});
test!(bin_there_for_integration {
.file("src/lib.rs", "");
assert_that(p.cargo_process("run").arg("--example").arg("foo"),
- execs().with_status(101).with_stderr("\
-no example target named `foo`
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} no example target named `foo`
+",
+ error = ERROR)));
assert_that(p.cargo_process("run").arg("--bin").arg("foo"),
- execs().with_status(101).with_stderr("\
-no bin target named `foo`
-"));
+ execs().with_status(101).with_stderr(&format!("\
+{error} no bin target named `foo`
+",
+ error = ERROR)));
});
test!(doctest_feature {